package com.site.util;

/**
 * 分页代码 
 * @author Believe fate
 * 
 */
public class Pager {
	/**
	 * 得到分页代码  
	 * @param url 分页请求URL
	 * @param startRow 分页开始记录数
	 * @param count 每页记录数
	 * @param countRow 总记录数
	 * @return output;
	 */
	public static String get_pager(String url,int startRow,int count,int countRow,int search){
		String output = null;
		// 当前页
		int pageNow = startRow/count + 1;
		// 总页数                        
		int pageCount = countRow%count;
		if(pageCount != 0){
			pageCount = countRow/count + 1;
		}else{
			pageCount = countRow/count;
		}
		if(count >= countRow){
		   output = "";
		}else{
		   output = "<div id='pager'>" +
					"<div class='pager-wapper'>" +
					    "<span>总页数："+pageCount+"</span>" +
					    "<span>当前页："+pageNow+"</span>" +
		            	"<!-- 请求的URL -->" +
			            "<input id='action_url' type='hidden' value='"+url+"'/>" +
					    "<!-- 每页记录数 -->" +
					    "<input id='page_num' type='hidden'value='"+count+"' />" +
                        "<!-- 总记录数 -->" +
                        "<input id='contRow' type='hidden'value='"+countRow+"' />" +
			            "<!-- 当前页-->" +
			            "<input id='page_now' type='hidden' value='"+pageNow+"'/>" +
			            "<!-- 是否为查询分页 -->" +
			            "<input id='search' type='hidden' value='"+search+"'/>" +
			            "<!-- 总页数-->" +
			            "<input id='page_count' type='hidden' value='"+pageCount+"' />" +
			            "<input id='page_first' class='page_btn' type='button' value='第一页' data-first='1'/>" +
			            "<input id='page_up' class='page_btn' type='button' value='上一页' />" +
			            "<input id='page_next' class='page_btn' type='button' value='下一页' />" +
			            "<input id='page_last' class='page_btn' type='button' value='最后一页' data-last='"+pageCount+"' />" +
			         "</div>" +
	              "</div>";
		}
		return output;
	}
}
